using System.Data.SqlClient;
using System.Configuration;

namespace Caam.Framework.Common
{
    public class ConnectionProvider
    {
        private static ConnectionProvider connProvider = new ConnectionProvider(); 

        private SqlConnection sqlConn = null;//new SqlConnection();
                                          
        private ConnectionProvider()
        {
        }

        public static ConnectionProvider Get_Instance()
        {
            if (connProvider == null)
            {
                connProvider = new ConnectionProvider();
            }
            return connProvider;
        }

        public SqlConnection GetSqlConnection()
        {
            sqlConn = new SqlConnection(this.Get_ConnectionString_FromConfigurationFile(string.Empty));
            return sqlConn;
        }

        public SqlConnection GetSqlConnection(string connectStringKey)
        {
            sqlConn = new SqlConnection(this.Get_ConnectionString_FromConfigurationFile(connectStringKey));
            return sqlConn;
        }

        private string Get_ConnectionString_FromConfigurationFile(string connectStringKey)
        {
            string connectionString = this.GetConnString(connectStringKey);
            return connectionString;
        }

        //06/08/2009
        public string GetConnString(string connectStringKey)
        {
            if (string.IsNullOrEmpty(connectStringKey))
                connectStringKey = "ConnectionString";
            return ConfigurationManager.ConnectionStrings[connectStringKey].ConnectionString;
        }
    }
}
